package com.jcl.recruit.crawler.logic;

import com.jcl.core.utils.CollectionUtils;
import com.jcl.recruit.crawler.dao.CrawlerDownloadResumeFeedbackDao;
import com.jcl.recruit.crawler.model.CrawlerDownloadResumeFeedback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @ClassName CrawlerDownloadResumeFeedbackLogic

 * @Author yyliu
 * @Date 2018/12/5 16:50
 * @Version 1.0
 **/
@Component
public class CrawlerDownloadResumeFeedbackLogic {

    @Autowired
    private CrawlerDownloadResumeFeedbackDao crawlerDownloadResumeFeedbackDao;

    public List<Integer> getStatusListByResumeId(String corpCode, Integer resumeId) {
        List<Integer> list = new ArrayList<>();
        List<CrawlerDownloadResumeFeedback> dataList =
                crawlerDownloadResumeFeedbackDao.findListByResumeId(corpCode, resumeId);
        if (CollectionUtils.isNotEmpty(dataList)) {
            for (CrawlerDownloadResumeFeedback entity : dataList) {
                list.add(entity.getStatus());
            }
        }
        return list;
    }

    public List<Integer> getStatusListByCrawlerId(String corpCode, Integer crawlerId) {
        List<Integer> list = new ArrayList<>();
        List<CrawlerDownloadResumeFeedback> dataList =
                crawlerDownloadResumeFeedbackDao.findListByCrawlerId(corpCode, crawlerId);
        if (CollectionUtils.isNotEmpty(dataList)) {
            for (CrawlerDownloadResumeFeedback entity : dataList) {
                list.add(entity.getStatus());
            }
        }
        return list;
    }

    public List<CrawlerDownloadResumeFeedback> findListByResumeId(String corpCode, Integer resumeId) {
        return crawlerDownloadResumeFeedbackDao.findListByResumeId(corpCode, resumeId);
    }

    public List<CrawlerDownloadResumeFeedback> findListByCrawlerId(String corpCode, Integer crawlerId) {
        return crawlerDownloadResumeFeedbackDao.findListByCrawlerId(corpCode, crawlerId);
    }

    public int add(CrawlerDownloadResumeFeedback crawlerDownloadResumeFeedback) {
        return crawlerDownloadResumeFeedbackDao.add(crawlerDownloadResumeFeedback);
    }

    public int add(String corpCode,
                   Integer crawlerId,
                   Integer resumeId,
                   Integer status) {
        CrawlerDownloadResumeFeedback feedback = new CrawlerDownloadResumeFeedback();
        feedback.setCorpCode(corpCode);
        feedback.setCrawlerId(crawlerId);
        feedback.setResumeId(resumeId);
        feedback.setStatus(status);
        feedback.setCreateTime(new Date());
        return crawlerDownloadResumeFeedbackDao.add(feedback);
    }
}
